package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Order;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author zsk
 * @create 2022-02-20-12:38
 */
@RestController
public class CartController {

    //依赖注入
    @Autowired
    private OrderService orderService;

    /*
    查看订单信息
    Request URL: http://localhost:8080/order/page?page=1&pageSize=10
    Request Method: GET
     */
    @GetMapping("/order/page")
    public ResultInfo findByPageOrder(
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date beginTime,//todo 想到根据时间查询，不会写
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime,
            @RequestParam(value = "page",defaultValue = "1") Integer pageNum,//代表第几页
            @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,//代表一页多少条数据
            Integer number ){//订单号

        Page<Order> page = orderService.findByPageOrder(pageNum,pageSize,number,beginTime,endTime);

        //返回结果
        return ResultInfo.success(page);

    }

}
